package com.lagou.app;

import com.lagou.dao.UserDao;
import com.lagou.entity.User;
import com.lagou.utils.DateUtils;
import com.lagou.utils.UUIDUtils;
import org.junit.Test;

import java.sql.SQLException;

/**
 * @Author wsl
 * @Date 2021/8/25 21:00
 * @Project_Name mysql
 */
public class TestUserDao {

    UserDao userDao = new UserDao();

    //1.测试注册用户
    @Test
    public void testRegister() throws SQLException {
        //1.创建user对象
        User user = new User();
        user.setUid(UUIDUtils.getUUID());
        user.setUsername("武松");
        user.setPassword("123456");
        user.setTelephone("12345678654");
        user.setBirthday(DateUtils.getDateFormart());
        user.setSex("男");

        //2.执行注册
        int register = userDao.register(user);

        if (register>0){
            System.out.println("注册成功！恭喜您："+ user.getUsername());
        } else {
            System.out.println("注册失败！");
        }
    }

    //2.测试用户登录
    @Test
    public void testLogin() throws SQLException {
        //1.执行登录
        User user = userDao.login("武松","123456");

        if (user != null){
            System.out.println("登录成功！欢迎您："+ user.getUsername());
        } else {
            System.out.println("用户名或密码错误，请重新登录。。。");
        }
    }
}
